package com.njit.mailm.core.service.impl;

import javax.print.attribute.ResolutionSyntax;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.njit.mailm.core.bean.Person;
import com.njit.mailm.core.bean.User;
import com.njit.mailm.core.dao.UserDao;
import com.njit.mailm.core.service.UserService;

@Transactional
@Service
public class UserServiceImpl implements UserService {

	@Autowired
	private UserDao userDao;

	public void saveUser(User user) throws Exception {
		userDao.saveUser(user);
	}

	@Transactional(readOnly = true)
	public boolean comparePwd(String username, String password) {
		User user = userDao.findUserByUsername(username);
		if (user == null) {
			return false;
		}
		return user.getPassword().equals(password);
	}

	public void setAuth(String username) throws Exception {
		userDao.setAuth(username);
	}

	public User getUserByUsername(String username) {
		return userDao.findUserByUsername(username);
	}

	public User comparePwd(User user) {
		User result = userDao.getUserByUandP(user);
		return result;
	}

}
